package it.fantacalcio.struts.action.user.account;

import it.fantacalcio.model.User;
import it.fantacalcio.struts.form.UserForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class PrepareEditAccountAction extends Action {
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		User userInSession = (User) request.getSession().getAttribute("userInSession");
		if(userInSession==null || userInSession.getAttivo().equals("NO")){
			return mapping.findForward("noninsession");
		}
		UserForm userForm = (UserForm) form;
		User user = new User();
		try {
			user = (User) request.getSession().getAttribute("userInSession");
			BeanUtils.copyProperties(userForm, user);
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("error");
		}
		return mapping.findForward("modifica");
		
	}

}
